<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ingesup {

    public function __construct() {
        $this->ci =& get_instance();
    }

    public function render($view, $data='') {
        $controller = $this->ci->router->fetch_class();
        $action = $this->ci->router->fetch_method();

        $hdata['title'] = lang('title'.'_'.$controller.'_'.$action);
        $hdata['stylesheets'] = array('bootstrap.min', /*'bootstrap-responsive.min',*/ 'all');
        $hdata['javascripts'] = array('jquery', 'bootstrap.min');

        if(is_file('css/'.$controller.'.css'))
            $hdata['stylesheets'][] = $controller;

        if(is_file('js/'.$controller.'.js'))
            $hdata['javascripts'][] = $controller;

        if($this->ci->tank_auth->is_logged_in()) {
            $data['user_id'] = $this->ci->tank_auth->get_user_id();
            $hdata['user_id'] = $data['user_id'];
            $hdata['user_fullname'] = $this->ci->user_profiles_model->get_user_fullname($hdata['user_id']);
            $sdata['role'] = $this->ci->tank_auth->get_role();
        } else
            $sdata = '';

        $fdata = '';

        if(isset($data['tabs']))
            $data['controller'] = $controller;

        $output =
            $this->ci->load->view('layout/header', $hdata, true).
            $this->ci->load->view('layout/sidebar', $sdata, true).
            $this->ci->load->view($view, $data, true).
            $this->ci->load->view('layout/footer', $fdata, true);

        $config = array(
            'indent' => true,
            'indent-spaces' => 4,
            'markup' => true,
            'new-blocklevel-tags' => 'article, aside, audio, canvas, datalist, details, figure, footer, header, hgroup, nav, ruby, section, video',
            'new-empty-tags' => 'embed, keygen, source, track, wbr',
            'new-inline-tags' => 'bdi, command, figcaption, mark, meter, output, progress, rp, rt, summary, time',
            'show-warnings' => true,
            'wrap' => 0,
            'write-back' => true,
        );

        echo tidy_repair_string($output, $config, 'utf8');
    }
}